package com.qiangqiang.repository;

import com.qiangqiang.entity.Student;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by q on 2018/2/1.
 */
@Repository
public interface StudentRepository extends JpaRepository<Student,String> {
    //增加一个学生

    /**
     * 根据sId 删除一个学生
     */
    @Modifying
    void deleteBySId(String sId);


    //修改一个学生的信息

    /**
     * 分页查询所有学生
     * @param pageable
     * @return
     */

    /**
     * 根据学生id查询学生
     * @param Id
     * @return
     */
    Student queryBySId(String id);

    /**
     * 根据学生姓名查询学生
     * @param name
     * @return
     */
    List<Student> queryAllByName(String name);

    /**
     * 使用自然连接：根据宿舍号查询该学生
     * @param dId
     * @return
     */
    @Query(value = "select * from student natural join dor_stu where d_id=:id",nativeQuery = true)
    List<Student> queryByDid(@Param("id") String dId);

    @Query(value = "select name from student where s_id=:id",nativeQuery = true)
    String queryNameBySId(@Param("id") String sId);
}
